<table class="editTable">
	<tr>
		<td style="text-align:right">模板</td>
		<td><input type="text" id="templateId" name="templateId"
			data-toggle="topjui-combotree"
			data-options="required:true,prompt:'必填',width:300,panelHeight:'auto',
				url:'/model/template/list/0',
				expandUrl:'/model/template/list/{id}',
				getFatherIdsUrl:'/model/template/getFatherIds/{id}',
				onChange:combotreeOnChange"></td>
	</tr>
	<tr>
		<td style="text-align:right">单元组</td>
		<td><input type="text" name="shapeIds" id="shapeIds"
			data-toggle="topjui-tagbox"
			data-options="width:300,panelHeight:'auto',hasDownArrow:true,editable:false,
				valueField:'id',textField:'name',url:'/model/shape/combo',
				onChange:tagboxOnChange"></td>
	</tr>
	<tr>
		<td style="text-align:right">名称</td>
		<td><input type="text" name="name"
			data-toggle="topjui-textbox"
			data-options="required:true,width:300,validType:'length[0,255]'"></td>
	</tr>
	<tr>
		<td style="text-align:right">备注</td>
		<td><input type="text" name="remark"
			data-toggle="topjui-textarea"
			data-options="width:300,validType:'length[0,255]'"></td>
	</tr>
</table>

<script type="text/javascript">

	var templateParams = [];
	var shapeParams = [];
	
	function combotreeOnChange(newValue, oldValue) {
		templateParams = [];
		if(newValue != null && newValue != undefined && newValue != "") {
			$.ajax({
				type : "get",
				url : "/model/neo4j/getAllParamNames?label=template&nodeUuid=" + newValue,
		        contentType: "application/json; charset=utf-8",
				success : function(result) {
					if(result.code == 200) {
						// 判断接口返回数据中是否存在params
						if(result.data != null && result.data.length > 0) {
							// 判断全局变量shapeParams中是否存在params，并判断是否有重复params
							if(shapeParams != null && shapeParams.length > 0 && isRepeat(shapeParams, result.data)) {
								templateParams = [];
								$('#templateId').iCombotree('clear');
								$.iMessager.alert('警告','关联参数重复，请重试！');
								return;
							}
							// 判断全局变量templateParams中是否存在params，并判断是否有重复params
							if(templateParams != null && templateParams.length > 0 && isRepeat(templateParams, result.data)) {
								templateParams = [];
								$('#templateId').iCombotree('clear');
								$.iMessager.alert('警告','关联参数重复，请重试！');
								return;
							}

							templateParams = result.data;
						}
					} else {
						templateParams = [];
						$('#templateId').iCombotree('clear');
						$.iMessager.alert('警告','接口返回错误，请重试！');
					}
				}, error : function() {
					templateParams = [];
					$('#templateId').iCombotree('clear');
					$.iMessager.alert('警告','接口返回错误，请重试！');
				}
			});
		}
	}

	function tagboxOnChange(newValues, oldValue) {debugger;
		shapeParams = [];
		if(newValues != null && newValues.length > 0) {
			for(var i=0; i<newValues.length; i++) {
				var newValue = newValues[i];
				$.ajax({
					type : "get",
					url : "/model/neo4j/getAllParamNames?label=shape&nodeUuid=" + newValue,
			        contentType: "application/json; charset=utf-8",
					success : function(result) {
						if(result.code == 200) {
							// 判断接口返回数据中是否存在params
							if(result.data != null && result.data.length > 0) {
								// 判断全局变量shapeParams中是否存在params，并判断是否有重复params
								if(shapeParams != null && shapeParams.length > 0 && isRepeat(shapeParams, result.data)) {
									shapeParams = [];
									$('#shapeIds').iCombobox('clear');
									$.iMessager.alert('警告','关联参数重复，请重试！');
									return;
								}
								// 判断全局变量templateParams中是否存在params，并判断是否有重复params
								if(templateParams != null && templateParams.length > 0 && isRepeat(templateParams, result.data)) {
									shapeParams = [];
									$('#shapeIds').iCombobox('clear');
									$.iMessager.alert('警告','关联参数重复，请重试！');
									return;
								}
								
								for(var i=0; i<result.data.length; i++) {
									shapeParams.push(result.data[i]);
								}
							}
						} else {
							shapeParams = [];
							$('#shapeIds').iCombobox('clear');
							$.iMessager.alert('警告','接口返回错误，请重试！');
							return;
						}
					}, error : function() {
						shapeParams = [];
						$('#shapeIds').iCombobox('clear');
						$.iMessager.alert('警告','接口返回错误，请重试！');
						return;
					}
				});
			}
		}
	}
	
	// 判断两个数组是有重复数据
	function isRepeat(list1, list2) {
		var flag = false;
		for(var i=0; i<list1.length; i++) {
			if(list2.indexOf(list1[i])  > -1) {
				flag = true;
				break;
			}
		}
		return flag;
	}
</script>